local goconf = require "goconf"
local skynet = require "skynet"

local cli
function init(...)
    local host, secret = ...
    local opt = {
        host = host,
        secret = secret,
    }

    local err
    cli, err = goconf.new(opt)
    if not cli then
        skynet.error("goconf init wrong, ", err)
        return
    end
end

function exit()
    skynet.error("goconfd exit success")
end

function response.get(key)
    return cli:query("get",{key=key})
end

function response.set(key, value, ttl)
    return cli:set(key, value, ttl)
end

function response.dir(key, level)
    return cli:query("dir",{key=key,level=level})
end

function response.delete(key)
    return cli:query("delete",{key=key})
end

function response.ttl(key, ttl)
    return cli:query("ttl",{key=key,ttl=ttl})
end

function response.since(key, rev)
    return cli:query("since",{key=key,since=rev})
end

function response.revision(key)
    return cli:query("revision",{key=key})
end

function response.range(s, e)
    return cli:query("range",{["start"]=s,["end"]=e})
end